package com.serwer;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;

import com.notowania.*;

public class ProducerNotow {

	 public void produceMessage(String queueName, Notowania notow){
         
	        //Create ConnectionFactory
	        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
	         
	        try{
	            //Create Connection using the factory
	            Connection connection = connectionFactory.createConnection();
	            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	            //Create Queue
	            Destination destQueue = session.createQueue(queueName);
	            //Create Producer
	            MessageProducer producer = session.createProducer(destQueue);
	            //Create Message
	            ObjectMessage message = session.createObjectMessage(notow);
	            //Send Message
	            producer.send(message);
	            //Close Producer
	            producer.close();
	            //Close Session
	            session.close();
	            //Close Connection
	            connection.close();          
	        }catch(JMSException e){         
	            System.out.println("Problem with ActiveMQ");  
	            e.printStackTrace();
	        }  
	    }

}
